using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections;

namespace Dragoon.RoboBattle
{
  interface IRobot
  {
    Vector3 Position { get; }
    /// <summary>
    /// Rotation around the Up Axis, 0 radians means North
    /// </summary>
    float Rotation { get; } 
  }

  interface ISimulator
  {
    IEnumerable<IRobot> Robots { get; }
  }

  namespace Simulator
  {
    class Robot : IRobot
    {
      static readonly Vector2 _north2D = new Vector2(Measurements.North.X,Measurements.North.Z);
      private Vector3 _position = Vector3.Zero;
      private Vector2 _orientation = _north2D;

      public Vector3 Position
      {
        get { return _position; }
        set { _position = value; }
      }

      public float Rotation
      {
        get
        {
          return  _north2D.AngleTo(_orientation);
        }
      }
    }

    class RobotSimulator : GameComponent, ISimulator
    {
      readonly Terrain _terrain;
      public List<Robot> Robots = new List<Robot>();
      public RobotSimulator(Game g, Terrain t) : base(g) { _terrain = t; }

      public override void Initialize()
      {
        int y = _terrain.Width / 2;
        for (int i = 1; i < _terrain.Width; i++)
          Robots.Add(new Robot
          {
            Position = _terrain.PositionAt(i, y),
          });
        base.Initialize();
      }    

      IEnumerable<IRobot> ISimulator.Robots
      {
        get 
        { 
          foreach (var r in Robots)
            yield return r;
        }
      }

      public override void Update(GameTime gameTime)
      {
        base.Update(gameTime);
      }
      
    }
  }
}
